package com.example.popupdialogdemo.slice;

import com.example.popupdialogdemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.PopupDialog;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        // 获取Text组件实例对象
        Text text = (Text) findComponentById(ResourceTable.Id_text_helloworld);
        // 添加点击事件监听
        text.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                // 点击文本后弹出PopupToast
                // 新建PopupToast实例，第1个参数为context上下文对象，第2个参数为锚点组件对象
                PopupDialog popupDialog = new PopupDialog(getContext(), text);
                // 设置文本
                popupDialog.setText("气泡对话框");
                // 设置背景色
                popupDialog.setBackColor(Color.CYAN);
                // 设置是否显示箭头
                popupDialog.setHasArrow(true);
                // 设置箭头尺寸
                popupDialog.setArrowSize(60, 60);
                // 设置锚定模式
                popupDialog.setMode(LayoutAlignment.TOP);




                // 弹出对话框
                popupDialog.show();
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
